<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="sendEvent">空间资源</el-button>
				<el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length==0" @click="batch_del"></el-button>
			</div>
			<div class="right-panel">
				<!-- <el-form-item label="牵头人" style="padding-top: 20px;">
					<select-user-dialog v-model:accountId="search.handedUser" :mode="false"/>
				</el-form-item> -->
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="输入园区名称"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" stripe remoteSort remoteFilter>
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="空间名称" prop="room" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="所属楼宇" prop="building_id" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="所在楼层/楼宇总层数" prop="floor" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="空间面积" prop="room_size" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="所属园区" prop="park_id" width="150" :show-overflow-tooltip="true"></el-table-column>
				<!-- <el-table-column label="所属片区" prop="area_id" width="150" :show-overflow-tooltip="true"></el-table-column> -->
				<el-table-column label="产业定位" prop="industry_positioning" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="功能类别" prop="function_type" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="装修状态" prop="renovation_type" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="租金定价" prop="rental_pricing" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="物业费" prop="strata_fees" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="是否推荐" prop="recommended" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="招商状态" prop="investment_policy" width="150" :show-overflow-tooltip="true"></el-table-column>
				<!-- <el-table-column label="事件类型" prop="typeName" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="督查领导" prop="leadUserName" width="100"></el-table-column>
				<el-table-column label="状态" prop="status" width="100"> 
				<el-table-column>
					<template #default="scope">
						<el-tag v-if="scope.row.status=='0'">进行中</el-tag>
						<el-tag v-if="scope.row.status=='1'" type="warning">延期中</el-tag>
						<el-tag v-if="scope.row.status=='2'" type="success">已完成</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="牵头人" prop="handedUserName" width="100"></el-table-column>
				<el-table-column label="开始时间" prop="beginTime" width="150"></el-table-column>
				<el-table-column label="结束时间" prop="endTime" width="150"></el-table-column>
				<el-table-column label="完成时间" prop="finishTime" width="150"></el-table-column>
				<el-table-column label="任务摘要" prop="subheading" width="200" :show-overflow-tooltip="true"> 
				</el-table-column>-->
				<el-table-column label="操作" fixed="right" align="right" width="165">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
							<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>
	<finishDialog v-if="dialog.finish" ref="finishDialog" @success="handleSaveSuccess" @closed="dialog.finish=false"></finishDialog>
	<recordDetails v-if="dialog.detailsSave" ref="recordDialog" @closed="dialog.detailsSave=false"></recordDetails>
	<processDialog v-if="dialog.processSave" ref="processDialog" @closed="dialog.processSave=false"></processDialog>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import selectUserDialog from "@/views/module/selectUserDialog";
import saveDialog from './save'
import recordDetails from "./details";
import finishDialog from './finish'
import processDialog from './process'
export default {
	name: 'Create Supervision Manage',
	components: {
		saveDialog,
		scSelectFilter,
		selectUserDialog,
		finishDialog,
		recordDetails,
		processDialog
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave: false,
				finish:false
			},
			filterData: [
				// {
				// 	title: "所属片区",
				// 	key: "date",
				// 	multiple: false,
				// 	options: [
				// 		{
				// 			label: "全部",
				// 			value: ""
				// 		}					
				// 	]
				// },
				// {
				// 	title: "所属园区",
				// 	key: "type",
				// 	multiple: false,
				// 	options: [{
				// 		label: "全部",
				// 		value: ""
				// 	}]
				// },
				// {
				// 	title: "所属楼宇",
				// 	key: "type1",
				// 	multiple: false,
				// 	options: [{
				// 		value: '全部',
				// 		label: ''
				// 	}],
				// },
				{
					title: "功能类别",
					key: "type2",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}, {
						value: '0',
						label: '办公'
					}, {
						value: '1',
						label: '科研'
					}, {
						value: '2',
						label: '商业'
					},{
						value: '3',
						label: '金融'
					},{
						value: '4',
						label: '公共'
					}
				],
				},
				{
					title: "空间面积",
					key: "type3",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}, {
						value: '0',
						label: '100平米以下'
					}, {
						value: '1',
						label: '100-200平米'
					}, {
						value: '2',
						label: '100-200平米'
					},{
						value: '3',
						label: '200-1000平米'
					},{
						value: '4',
						label: '1000平米以上'
					}
				],
				},
				{
					title: "租金区间",
					key: "type4",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}, {
						value: '0',
						label: '3-4元/平米/天'
					}, {
						value: '1',
						label: '3-4元/平米/天'
					}, {
						value: '2',
						label: '3-4元/平米/天'
					},{
						value: '3',
						label: '3-4元/平米/天'
					},{
						value: '4',
						label: '3-4元/平米/天'
					}
				],
				},
				{
					title: "租售情况",
					key: "type5",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}, {
						value: '0',
						label: '分层出售'
					}, {
						value: '1',
						label: '整栋出售'
					}, {
						value: '2',
						label: '分层出租'
					},{
						value: '3',
						label: '整栋出租'
					}
				],
				},{
					title: "空置情况",
					key: "type6",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					}, {
						value: '0',
						label: '50%以下'
					}, {
						value: '1',
						label: '50%以上'
					}, {
						value: '2',
						label: '无空置'
					}
				],
				}

			],
			apiObj: this.$API.attractinvestment.space.getSpaceList,
			selection: [],
			search: {
				date: '',
				type: '',
				status: '',
				handedUser: '',
				keyword: null
			}
		}
	},
	mounted() {
		this.getSpaceList();
	},
	methods: {
		async getSpaceList() {
			var res = await this.$API.attractinvestment.space.getSpaceList.get();
			if (res.code == 200) {
				this.filterData[1].options = this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//添加
		sendEvent() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			})
		},
		//编辑
		table_edit(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		setFinishStatus(row)
		{
			this.dialog.finish = true
			this.$nextTick(() => {
				this.$refs.finishDialog.open().setData(row);
			})
		},
		setProcess(row)
		{
			this.dialog.processSave = true
			this.$nextTick(() => {
				this.$refs.processDialog.open().setData(row);
			})
		},
		//查看
		table_show(row) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.recordDialog.open().setData(row)
			})
		},
		//删除
		async table_del(row) {
			var res = await this.$API.attractinvestment.space.deleteSpace.post({id: row.id});
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//批量删除
		async batch_del() {
			await this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
				type: 'warning'
			}).then(async () => {
				var spaceIdArr = [];
				for (var i = 0; i < this.selection.length; i++) {
					spaceIdArr.push(this.selection[i].supervisionId);
				}
				const loading = this.$loading();
				var res = await this.$API.supervision.attractinvestment.space.deleteSpaceByIds.post({ids: spaceIdArr});
				if (res.code == 200) {
					this.$refs.table.refresh()
					this.$message.success(res.message)
				} else {
					this.$alert(res.message, "提示", {type: 'error'})
				}
				loading.close();
			}).catch(() => {

			})
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data) {
			this.search.date = data.date;
			this.search.type = data.type;
			this.search.status = data.status;
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		},
	}
}
</script>

<style>
</style>
